#include "utils.hpp"

std::tuple<std::string, std::string, std::string>
url_split(const std::string &url)
{
    std::regex pattern("^(.*)://([a-zA-Z-.]{1,})(/.*)?$");
    std::smatch groups;
    bool is_match = std::regex_match(url, groups, pattern);
    std::string protocol = groups[1], host = groups[2], path = groups[3];
    if (protocol.empty())
    {
        protocol = "http";
    }
    if (path.empty())
    {
        path = "/";
    }
    return std::make_tuple(protocol, host, path);
}

Counter::Counter()
{
    success_cnt.store(0, std::memory_order::memory_order_seq_cst);
    failed_cnt.store(0, std::memory_order::memory_order_seq_cst);
    total_cnt.store(0, std::memory_order::memory_order_seq_cst);
}

void Counter::success()
{
    success_cnt += 1;
    total_cnt += 1;
}
void Counter::failed()
{
    failed_cnt += 1;
    total_cnt += 1;
}
std::tuple<int, int, int> Counter::summary()
{
    return std::make_tuple<int, int, int>(
        total_cnt.load(),
        success_cnt.load(),
        failed_cnt.load()
    );
}